(function (vc, vm) {

    vc.extends({
        data: {
            editAffiliateProductInfo: {
                apId: '',
                productId: '',
                seq: '',

            }
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('editAffiliateProduct', 'openEditAffiliateProductModal', function (_params) {
                vc.component.refreshEditAffiliateProductInfo();
                $('#editAffiliateProductModel').modal('show');
                vc.copyObject(_params, vc.component.editAffiliateProductInfo);
                vc.component.editAffiliateProductInfo.communityId = vc.getCurrentCommunity().communityId;
            });
        },
        methods: {
            editAffiliateProductValidate: function () {
                return vc.validate.validate({
                    editAffiliateProductInfo: vc.component.editAffiliateProductInfo
                }, {
                    'editAffiliateProductInfo.productId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "分销商品不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "分销商品不能超过30"
                        },
                    ],
                    'editAffiliateProductInfo.apId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "分销商品ID不能为空"
                        }]

                });
            },
            editAffiliateProduct: function () {
                if (!vc.component.editAffiliateProductValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }

                vc.http.apiPost(
                    'affiliateProduct.updateAffiliateProduct',
                    JSON.stringify(vc.component.editAffiliateProductInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editAffiliateProductModel').modal('hide');
                            vc.emit('affiliateProductManage', 'listAffiliateProduct', {});
                            return;
                        }
                        vc.message(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.message(errInfo);
                    });
            },
            refreshEditAffiliateProductInfo: function () {
                vc.component.editAffiliateProductInfo = {
                    apId: '',
                    productId: '',
                    seq: '',

                }
            }
        }
    });

})(window.vc, window.vc.component);
